package com.chen.controller;

import com.chen.anno.Log;
import com.chen.pojo.ClassQueryParam;
import com.chen.pojo.ClassRoom;
import com.chen.pojo.PageResult;
import com.chen.pojo.Result;
import com.chen.service.ClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClassController {
    @Autowired
    private ClassService classService;
    /*
    分页查询
     */
    @GetMapping()
    public Result list(ClassQueryParam classQueryParam){
        log.info("分页查询员工信息,参数:{}", classQueryParam);
        PageResult<ClassRoom> pageResult = classService.page(classQueryParam);
        return Result.success(pageResult);
    }
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除班级信息,参数:{}", id);
        classService.delete(id);
        return Result.success();
    }
    @Log
    @PostMapping
    public Result add(@RequestBody ClassRoom classRoom){
        log.info("添加班级信息,参数:{}", classRoom);
        classService.add(classRoom);
        return Result.success();
    }
    /*
    获取班级信息根据ID
     */
    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id){
        log.info("获取班级信息,参数:{}", id);
        ClassRoom classRoom = classService.getInfoById(id);
        return Result.success(classRoom);
    }
    @Log
    @PutMapping
    public Result updateEmpInfo(@RequestBody ClassRoom classRoom){
        log.info("修改班级信息,参数:{}", classRoom);
        classService.updateInfo(classRoom);
        return Result.success();
    }
    @GetMapping("/list")
    public Result list(){
        log.info("获取全部班级列表");
        return Result.success(classService.findall());
    }
}
